import type { AxiosPromise } from "axios";
import axios from "axios";
import { apiInstance } from "./base";
import store from "@/app/store";

export type getHeroesListParams = {
  search?: string;
};

export const getHeroesList = (params?: getHeroesListParams): AxiosPromise => {
  return apiInstance.get(`?${params ? new URLSearchParams(params) : ""}`);
};

export type getHeroByIdParams = {
  heroId: string;
};

export const getHeroInfoById = ({ heroId }: getHeroByIdParams): AxiosPromise => {
  return apiInstance.get(`/${heroId}`);
};

export const getHeroesMore = (nextPageUrl: string): AxiosPromise => {
  return axios.get(nextPageUrl);
};

export const getInfoByUrl = async (url: string) => {
  return axios.get(url);
};

export type AppDispatch = typeof store.dispatch;
